/**
author: sailing
date: 2016/11/17
fun： 获取数据去画topo
***/
import fetchJson from './fetchJson'
import tools from './tools'
import Config from './config'
import data from './data'
import eventBus from '../eventBus'
import resetData from './resetData'
export default {
    start(vm, data) {
        this.vm = vm
        this.data = data
            // this.callback([{id: '777144', label: '555'}])
        this.getShortPath()
    },

    judge() {
        /*
        var nodes = data.nodes

        for (var i=0; i<nodes.length; i++) {
          var nodeType = nodes[i].data
          console.log('this.data.source.toString() === nodeType.id.toString()', this.data.source.toString() === nodeType.id.toString())
          if (this.data.source.toString() === nodeType.id.toString() || this.data.target.toString() === nodeType.id.toString()) {
            if (nodeType.type === 'distributing_cabinet') return false
          } 
          // console.log('node.id distributing_cabinet:', nodeType, nodes[i].type)
        }
        return true
        */
    },

    getShortPath(id, cy) {
        this.cy = cy
            // var url = tools.mergeUrl('shortPath')
        var url = '/topology/node_path/?start_equipment_id=' + this.data.source + '&end_equipment_id=' + this.data.target + '&start_port_serial=' + this.data.s_port_serial + '&end_port_serial=' + this.data.e_port_serial
            // var url = 'nodePath?source' + this.data.source + '&target=' + this.data.target  

        fetchJson.getJson({
            self: this,
            url: url,
            callback: this.callback,
            error: this.error
        })
    },

    reSet() {

    },

    setLabel(node, label, color) {
        node.style({
            'color': color,
            'content': label
        })
    },

    callback_() {

    },

    callback(json) {
        var jData = json.data
        var that = this
        console.log('Config.topVue.$message(没有异常端口);: ', json)
        if (json.code === 0) {
            Config.topVue.$message(json.message)
            return
        }

        data.cy.nodes(function(i, node) {
            var nodeData = node.data()
            that.setLabel(node, data.oldLabel, '#000')
            for (var j = 0; j < jData.length; j++) {
                if (jData[j]['id'].toString() === nodeData.id.toString()) {
                    var label = nodeData.label + '||' + jData[j]['port_name']
                    that.setLabel(node, label, '#FF7F24')
                }
            }
        })
    },
    error() {}

}